<template>
  <div class="goods">
    <div class="wrap">
      <!-- 导航信息!!!!! -->
      <Crumb1> </Crumb1>
      <img src="../assets/img/banner.4c6b6225.png" width="100%" alt="" />
      <ul class="options">
        <li>
          <strong>排序：</strong>

          <!-- 
              点击排序项 ， 得到当前min ，max 积分值，执行查询商品的方法
             {显示内容：‘500-1000’，min:500,max:1000}
           -->
          <span
            :class="{ active: index == options1Active }"
            v-for="(item, index) in options1"
            :key="index"
            @click="heavyload(index, item.min, item.max)"
            >{{ item.txt }}</span
          >
        </li>
        <li>
          <strong>分类：</strong>
          <!-- <span class="active">全部</span>
          <span>实物礼品</span>
          <span>虚拟礼品</span> -->
          <span
            :class="{ active: index == options2Active }"
            v-for="(item, index) in options2"
            :key="index"
            @click="heavyload1(index, item.type)"
            >{{ item.txt }}</span
          >
        </li>
      </ul>
      <List :data="goodsList" />
    </div>
  </div>
</template>                            
<script>
import Crumb1 from '../components/Crumb1.vue'
import List from '../components/Home/List.vue'
import { GoodsSearchAPI } from '@/request/api'
export default {
  data() {
    return {
      //栏目  0全部  1 精品 2 热门
      did: 0,
      //类型  0全部 1实体 2 虚拟
      type: 0,
      //最小积分值
      min: 0,
      //最大积分值   值为0 与逻辑无关
      max: 10000,
      //搜索关键字
      keyword: '',
      //商品arr
      goodsList: [],
      //排序项数组
      options1: [
        { min: 0, max: 10000, txt: '全部' },
        // "我还可以兑换"的max值是Header组件的coin值
        { min: 0, max: 0, txt: '我还可以兑换' },
        { min: 0, max: 500, txt: '0-500分' },
        { min: 500, max: 1000, txt: '500-1000分' },
        { min: 1000, max: 1500, txt: '1000-1500分' },
        { min: 1500, max: 2500, txt: '1500-2500分' },
        { min: 2500, max: 6500, txt: '2500-6500分' },
        { min: 6500, max: 10000, txt: '6500-10000分' }
      ],
      options2: [
        { txt: '全部', type: 0 },
        { txt: '实物礼品', type: 1 },
        { txt: '虚拟礼品', type: 2 }
      ],
      options1Active: 0,
      options2Active: 0
    }
  },
  components: {
    Crumb1,
    List
  },
  created() {
    this.keyword = this.$route.query.keyword
    this.getGoods()
  },
  watch: {
    '$route.query.keyword': {
      handler(n, o) {
        this.keyword = n
        this.getGoods()
      }
    }
  },
  methods: {
    async getGoods() {
      let res = await GoodsSearchAPI({
        did: this.did,
        type: this.type,
        min: this.min,
        max: this.max,
        keyword: this.keyword
      })
      console.log(res)
      this.goodsList = res.data.data
      console.log(this.goodsList)
    },
    heavyload(i, min, max) {
      console.log(111)
      this.options1Active = i
      this.min = min
      this.max = max
      this.getGoods()
    },
    heavyload1(i, type) {
      this.options2Active = i
      this.type = type
      this.getGoods()
    }
  }
}
</script>
 
<style lang = "less" scoped>
@import '../assets/css/public.less';
@base-color: #0a328e;
.goods {
  padding-bottom: 50px;
  background: #efefef;
  padding-top: 20px;
  .options {
    padding-top: 20px;
    padding-bottom: 40px;
    li {
      margin-top: 20px;
      strong {
        color: #000;
        font-weight: bold;
      }
      span {
        margin-right: 20px;
        margin-left: 10px;
        cursor: pointer;
        color: #999;
        &.active {
          color: @base-color;
          font-weight: bold;
        }
      }
    }
  }
}
</style>